import * as ACTIONS from '../../actions/independent-practice/depthMissionAction';

/**
 * 数据视图默认状态
 * @type {Object}
 */
export const DEFAULT_DATA_STATE = {
	message: '',
	isFetching: false,
	averageCountData: [
		// 平均闯关数
	],
	averageTimesData: [
		// 平均闯关次数
	],
	summary: [
		// 汇总
	]
};

export function depthMissionReducer(state = DEFAULT_DATA_STATE, action = {}) {
	let { type, payload } = action;
	switch(type) {
		case ACTIONS.GET_RETAINED_DATA_REQUEST:
			return Object.assign({}, state, {
				isFetching: true,
				averageCountData: [],
				averageTimesData: [],
				summary: []
			});
		case ACTIONS.GET_RETAINED_DATA_SUCCESS:
			return Object.assign({}, state, {
				isFetching: false,
				averageCountData: payload.averageCountData,
				averageTimesData: payload.averageTimesData,
				summary: payload.summary
			});
		case ACTIONS.GET_RETAINED_DATA_FAILURE:
			return Object.assign({}, state, {
				message: payload.message,
				isFetching: false,
				averageCountData: [],
				averageTimesData: [],
				summary: []
			});
		default:
			return state;
	}
};